/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package titanisu.templates.helperClasses;

import java.util.Random;

/**
 *
 * @author Balaji
 */
public class VariablesHelper {

    public String getOperator(String operator) {
        String op = "";
        double rnd = Math.random();

        if (operator == "opPM") {
            if (rnd > 0.5) {
                return "+";
            } else {
                return "-";
            }
        }

        if (operator == "*/") {
            if (rnd > 0.5) {
                return "*";
            } else {
                return "/";
            }
        }

        return operator;

    }

    public String getRandomOperator(String opList) {
        String retOp = "";
        retOp = String.valueOf(opList.charAt(new Random().nextInt(opList.length())));
        return retOp;
    }

    public String replaceMMLVariablesSimple(String content) {

        titanisu.mathUtil.NumberFetcher nf = new titanisu.mathUtil.NumberFetcher();
        String[] vars = content.split("titns");
        int varCount = vars.length / 2 + ((vars.length) % 2);
        int[] variable = nf.getNDiffnumbers(varCount, 30);
        for (int i = 0; i < varCount; i++) {
            content = content.replaceAll("titns" + (i + 1) + "titns", "" + variable[i]);
        }

        String opr = getOperator("--");
        content = content.replaceAll("--", opr);

        return content;

    }
}
